#!/bin/bash
if [ -z "$1" ]; then
	echo "******使用帮助******
	ai lamp     命令重启lamp环境
	ai openvpn  命令重启openvpn服务
	ai reboot   命令重启服务器
	ai mysqloff 禁用phpmyadmin
	ai mysqlon  启用phpmyadmin
	ai opentcp  开启任意tcp端口
	ai openudp  开启任意udp端口
	ai appoff   关闭旧版云端app
	ai appon    开启旧版云端app"
fi
IPAddress=`wget http://ipinfo.io/ip -O - -q ; echo`;
if [[ $1 == "openvpn" ]]; then
	setenforce 0 >/dev/null 2>&1
	killall openvpn >/dev/null 2>&1
	killall -HUP proxy >/dev/null 2>&1
	killall squid >/dev/null 2>&1
	squid -z >/dev/null 2>&1
	squid -s >/dev/null 2>&1
	killall squid >/dev/null 2>&1
	squid -z >/dev/null 2>&1
	squid -s >/dev/null 2>&1
	service openvpn start >/dev/null 2>&1
	cd /etc/openvpn
	./proxy -l 8080 -d >/dev/null 2>&1
	echo
	sleep 2
	echo -e "服务状态：                    [\033[32m  OK  \033[0m]"
	echo "$(date +%Y-%m-%d~%H:%M:%S)服务重启成功" >>/etc/openvpn/1.log
	exit 0;
fi

if [[ $1 == "reboot" ]]; then
	service openvpn stop
	echo "$(date +%Y-%m-%d~%H:%M:%S)服务器重启成功" >>/etc/openvpn/1.log
	reboot
fi

if [[ $1 == "lamp" ]]; then
	service httpd restart
	service mysql restart
	echo "$(date +%Y-%m-%d~%H:%M:%S)lamp重启成功" >>/etc/openvpn/1.log
fi


if [[ $1 == "mysqloff" ]]; then
	chmod -R 0000 /var/www/html/phpmyadmin
	echo "数据库管理工具已经关闭！"
fi


if [[ $1 == "mysqlon" ]]; then
	chmod -R 0777 /var/www/html/phpmyadmin
	echo "数据库管理工具重新开启！"
fi

if [[ $1 == "opentcp" ]]; then
	echo -e "请输入要开启的tcp端口：(默认已经开通137/138端口)"
	read part
	iptables -t nat -A PREROUTING -p tcp -m tcp --dport $part -j DNAT --to-destination $IPAddress:8080
	service iptables save&&service iptables restart
	echo 开启tcp：$part端口成功
fi

if [[ $1 == "openudp" ]]; then
	echo -e "请输入要开启的udp端口：(默认已经开通137/138端口)"
	read part
	iptables -t nat -A PREROUTING -p udp -m udp --dport $part -j DNAT --to-destination $IPAddress:137
	service iptables save&&service iptables restart
	echo 开启udp：$part端口成功
fi

if [[ $1 == "appoff" ]]; then
	chmod -R 0000 /var/www/html/linesadmin
	echo "旧版云端关闭"
fi

if [[ $1 == "appon" ]]; then
	chmod -R 0777 /var/www/html/linesadmin
	echo "旧版云端开启"
fi

exit 0